<template>
  <div class="movie-search-select-container">
    <div class="select-items" v-if="searchHistoryList.length > 0">
      <div class="head">
        <div class="name">历史搜索</div>
        <div class="btn" @click="movieStore.clear()">
          <Del2 color="#15181d" size="0.6rem" />
        </div>
      </div>
      <div class="content">
        <div
          class="item"
          v-for="(item, index) in searchHistoryList"
          :key="index"
          @click="handelclickSearch(item)"
        >
          <div class="txt">{{ item.name }}</div>
        </div>
      </div>
    </div>
    <!-- <div class="select-items" v-if="recommendList.length > 0">
      <div class="head">
        <div class="name">推荐搜索</div>
        <div class="btn">
        </div>
      </div>
      <div class="content">
        <div class="item" v-for="(item,index) in recommendList" :key="index">
          <div class="txt">{{item.name}}</div>
        </div>
      </div>
    </div> -->
  </div>
</template>
<script setup>
import { ref, reactive, toRefs, onMounted, watch } from "vue";
import { Del2 } from "@nutui/icons-vue-taro";
import { storeToRefs } from "pinia";
import { useMovieStore } from "../../store";
import * as movieApi from "../../api/movie";
import Taro from "@tarojs/taro";

const movieStore = useMovieStore();
const { searchHistoryList } = storeToRefs(movieStore);
const recommendList = ref([{ name: "推荐电影1" }, { name: "推荐电影2" }]);
const searchList = ref([]);
const emit = defineEmits(["onSearched"]);
const handelclickSearch = (item) => {
  console.log(item, "---");

  let data = {
    name: item.name,
  };
  console.log(data, "向父组件");
  emit("onSearched", data);
};
</script>
<style lang="scss">
.movie-search-select-container {
  display: flex;
  flex-direction: column;
  .select-items {
    display: flex;
    flex-direction: column;
    .head {
      display: flex;
      flex-direction: row;
      align-items: center;
      padding: 0 0.8rem;
      height: 2.5rem;
      .name {
        flex: 1;
        font-size: 0.6rem;
        color: #15181d;
      }
      .btn {
        width: 2rem;
        height: 100%;
        display: flex;
        flex-direction: row;
        justify-content: center;
        align-items: center;
      }
    }
    .content {
      direction: ltr;
      padding: 0 0.8rem;
      .item {
        display: inline;
        .txt {
          background: #ffffff;
          border-radius: 0.2rem;
          font-size: 0.6rem;
          padding: 0.2rem 0.4rem;
          color: #858a99;
          display: inline-flex;
          margin-right: 0.4rem;
          margin-bottom: 0.2rem;
        }
      }
    }
  }
}
</style>
